package md.frolov.bible.views;

import md.frolov.bible.editors.BibleReferenceSelection;

import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.part.ViewPart;

public class CommentariesView extends ViewPart {
	public final static String PLUGIN_ID= "md.frolov.bible.views.CommentariesView";
	
	StyledText styledText;

	
	@Override
	public void createPartControl(Composite parent) {
		FillLayout layout = new FillLayout();
		parent.setLayout(layout);
		styledText = new StyledText(parent,SWT.V_SCROLL | SWT.WRAP);
		
		hookSelectionListeners();
	}
	
	private void hookSelectionListeners(){
		getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(new ISelectionListener(){
			@Override
			public void selectionChanged(IWorkbenchPart part, ISelection selection) {
				if(selection instanceof BibleReferenceSelection){
					styledText.setText(((BibleReferenceSelection) selection).getReference());
				}
			}
			
		});
	}
	
	@Override
	public void setFocus() {
		// TODO Auto-generated method stub

	}

}
